<template>
  <div>
    <el-row style="margin-bottom:20px;display:flex;justify-content:space-between">
      <el-select v-model="searchData.ep_type" placeholder="请选择设备分类" style="margin-right:10px;width:20%" clearable>
        <el-option
          v-for="item in eqtypeArr"
          :key="item.value"
          :label="item.hash.code_name"
          :value="item.hash.code_id"
        ></el-option>
      </el-select>
      <el-select v-model="searchData.status" placeholder="请选择设备状态" style="margin-right:10px;width:20%" clearable>
        <el-option
          v-for="item in statusArr"
          :key="item.value"
          :label="item.hash.code_name"
          :value="item.hash.code_id"
        ></el-option>
      </el-select>
      <el-input placeholder="溯源方式" style="width:20%;margin-right:10px" v-model="searchData.traceability" clearable></el-input>
      <el-input placeholder="负责人" style="width:20%;margin-right:10px" v-model="searchData.charger" clearable></el-input>
      <el-input placeholder="使用人" style="width:20%;margin-right:10px" v-model="searchData.syrname" clearable></el-input>
      <el-input placeholder="规格型号" style="width:20%;margin-right:10px" v-model="searchData.scale" clearable></el-input>


    </el-row>
    <el-row style="margin-bottom:20px;display:flex;justify-content:space-between">
      <el-input placeholder="仪器设备名称" style="width:20%;margin-right:10px" v-model="searchData.ep_ename" clearable></el-input>
      <el-input placeholder="管理编号" style="width:20%;margin-right:10px" v-model="searchData.managenum" clearable></el-input>
      <el-input placeholder="出厂编号" style="width:20%;margin-right:10px" v-model="searchData.factory_num" clearable></el-input>
      <el-input placeholder="生产厂家" style="width:20%;margin-right:10px" v-model="searchData.factory" clearable></el-input>
      <el-input placeholder="检定/校准单位" style="width:20%;margin-right:10px" v-model="searchData.verifiy_company" clearable></el-input>
      <el-input placeholder="量值" style="width:20%;margin-right:10px" v-model="searchData.measurement" clearable></el-input>

    </el-row>

    <el-row style="margin-bottom:30px;display:flex;justify-content:flex-start">
      <el-input placeholder="放置地点" style="width:20%;margin-right:10px" v-model="searchData.location" clearable></el-input>
      <el-input placeholder="检测项目" style="width:20%;margin-right:10px" v-model="searchData.verifiy_project" clearable></el-input>
      <selectorg @getselectorgid="getselectorgid" style="width:20%;margin-right:10px"></selectorg>
      <el-date-picker
        v-model="jddate"
        clearable
        style="margin-right:15px;width:25%"
        type="daterange"
        rangeSeparator="至"
        startPlaceholder="本次检定/校准开始"
        endPlaceholder="本次检定/校准结束"
        valueFormat="yyyy-MM-dd"
      >
      </el-date-picker>
      <el-date-picker
        v-model="jddate2"
        clearable
        style="margin-right:10px;width:25%"
        type="daterange"
        rangeSeparator="至"
        valueFormat="yyyy-MM-dd"
        startPlaceholder="下次检定/校准开始"
        endPlaceholder="下次检定/校准结束"
      >
      </el-date-picker>
      <el-date-picker
        v-model="buydate"
        clearable
        style="margin-right:10px;width:25%"
        type="daterange"
        rangeSeparator="至"
        startPlaceholder="购置开始日期"
        endPlaceholder="购置开始日期"
        valueFormat="yyyy-MM-dd"
      >
      </el-date-picker>
      <el-button size="mini" type="primary" @click="geteqlist(1)">搜索</el-button>
    </el-row>

    <el-divider></el-divider>
    <eqtable :eqlist="eqlist" :pagobj="pagobj" :choosedp.sync="choosedp" :ismanager="false"></eqtable>
  </div>

</template>

<script>
import eqtable from '~/components/apparatus/eqmanager/eqtable.vue';
import selectorg from '~/components/common/selectorg.vue';

export default {
  props: {
    eqtype: {
      type: String,
      required: true,
    },
  },
  components: {
    eqtable,
    selectorg,
  },
  data() {
    return {
      ts: this.newStore(),
      title: '年度检定生成',
      isall: false,
      isneweq: false,
      isneweq2: false,
      isedit: false,
      showcheckeq: false,
      checkeqtime: '',
      editdata: {},
      choosedp: [],
      statusArr: [],
      eqtypeArr: [],
      jddate: ['', ''],
      jddate2: ['', ''],
      buydate: ['', ''],
      pagobj: {
        currentPage3: 1,
        pagesize: 10,
        total: 10,
      },
      eqlist: [],
      searchData: {
        ep_type: '',
        orgid: '',
      },
    };
  },
  created() {
    this.getcodeData('0403', '04', 'statusArr');
    this.getcodeData('0402', '04', 'eqtypeArr');
  },
  mounted() {
    this.searchData.ep_type = this.eqtype;
    // this.geteqlist();
  },
  methods: {
    getselectorgid(val) {
      this.searchData.orgid = val;
    },
    // 编辑人员
    editeq() {
      if (this.choosedp.length == 0) {
        this.$message({
          type: 'info',
          message: '请先勾选设备',
        });
        return;
      }
      if (this.choosedp.length > 1) {
        this.$message({
          type: 'info',
          message: '只能编辑一个设备',
        });
        return;
      }
      this.isedit = true;
      const req = {
        handle: 'DD5D108B99FC12B72DC0B97F927BBE3DD7F2412F8A4ED57CBFF0B9210751F692',
        id: this.choosedp[0].hash.id,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.editdata = ts.d.data;
        this.reload('isneweq2');
      });
    },
    // 公共方法获取代码项
    getcodeData(supid, codetype, arrname) {
      const req = {
        handle: '67A5B6FEF17D97DECF116BDF95B95C0B167942DD3F1604F9',
        supid,
        codetype,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this[arrname] = ts.d.data.operation1;
      });
    },
    // 获取设备列表
    geteqlist(p) {
      if (p) {
        this.pagobj.currentPage3 = p;
      }
      if (this.jddate == null) {
        this.jddate = [];
      }
      if (this.jddate2 == null) {
        this.jddate2 = [];
      }
      if (this.buydate == null) {
        this.buydate = [];
      }
      const req = this.searchData;
      req.handle = 'DD5D108B99FC12B72DC0B97F927BBE3D1A8639331D9DCC49';
      req.start = (this.pagobj.currentPage3 - 1) * this.pagobj.pagesize;
      req.limit = this.pagobj.pagesize;
      req.syrid = localStorage.getItem('pid');
      [req.verifiytime_begin] = [this.jddate[0]];
      [req.verifiytime_end] = [this.jddate[1]];
      [req.nextverifiytime_begin] = [this.jddate2[0]];
      [req.nextverifiytime_end] = [this.jddate2[1]];
      [req.verifiytime_begin] = [this.buydate[0]];
      [req.verifiytime_end] = [this.buydate[1]];
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.eqlist = ts.d.data.operation1;
        this.pagobj.total = parseInt(ts.d.data.operation2[0].hash.allrs);
      });
    },
    // 公共组件刷新方法
    reload(partsname) {
      this[partsname] = false;
      this.$nextTick(() => {
        this[partsname] = true;
      });
    },
  },
};
</script>

